{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "colab_type": "text",
        "id": "XUmNqU4FJm-Y"
      },
      "source": [
        "##### Copyright 2019 Google LLC."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 0,
      "metadata": {
        "cellView": "form",
        "colab": {},
        "colab_type": "code",
        "id": "fEIKi4xPLIhh"
      },
      "outputs": [],
      "source": [
        "#@title Licensed under the Apache License, Version 2.0 (the \"License\");\n",
        "# you may not use this file except in compliance with the License.\n",
        "# You may obtain a copy of the License at\n",
        "#\n",
        "# https://www.apache.org/licenses/LICENSE-2.0\n",
        "#\n",
        "# Unless required by applicable law or agreed to in writing, software\n",
        "# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
        "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
        "# See the License for the specific language governing permissions and\n",
        "# limitations under the License."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "colab_type": "text",
        "id": "4s5mp7vHPJZh"
      },
      "source": [
        "# Get Started with TensorFlow Graphics\n",
        "\u003ctable class=\"tfo-notebook-buttons\" align=\"left\"\u003e\n",
        "  \u003ctd\u003e\n",
        "    \u003ca target=\"_blank\" href=\"https://www.tensorflow.org/graphics\"\u003e\u003cimg src=\"https://www.tensorflow.org/images/tf_logo_32px.png\" /\u003eView on TensorFlow.org\u003c/a\u003e\n",
        "  \u003c/td\u003e\n",
        "  \u003ctd\u003e\n",
        "    \u003ca target=\"_blank\" href=\"https://colab.research.google.com/github/tensorflow/graphics/blob/master/tensorflow_graphics/g3doc/_index.ipynb\"\u003e\u003cimg src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" /\u003eRun in Google Colab\u003c/a\u003e\n",
        "  \u003c/td\u003e\n",
        "  \u003ctd\u003e\n",
        "    \u003ca target=\"_blank\" href=\"https://github.com/tensorflow/graphics/tree/master/tensorflow_graphics/g3doc/_index.ipynb\"\u003e\u003cimg src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" /\u003eView source on GitHub\u003c/a\u003e\n",
        "  \u003c/td\u003e\n",
        "\u003c/table\u003e"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "colab_type": "text",
        "id": "q4fzyll4LvQc"
      },
      "source": [
        "If Tensorflow Graphics and Trimesh are not installed on your system the following cell can install these packages for you."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 0,
      "metadata": {
        "colab": {},
        "colab_type": "code",
        "id": "IJihqZ7TLYCp"
      },
      "outputs": [],
      "source": [
        "!pip install tensorflow-graphics\n",
        "!pip install trimesh"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "colab_type": "text",
        "id": "St8jfrN0MfPs"
      },
      "source": [
        "Now that Tensorflow Graphics and Trimesh are installed, let's import everything needed."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 0,
      "metadata": {
        "colab": {},
        "colab_type": "code",
        "id": "Qy1CfOu7ioF8"
      },
      "outputs": [],
      "source": [
        "import numpy as np\n",
        "import tensorflow as tf\n",
        "import trimesh\n",
        "\n",
        "import tensorflow_graphics.geometry.transformation as tfg_transformation\n",
        "from tensorflow_graphics.notebooks import threejs_visualization"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "colab_type": "text",
        "id": "WvVeZ1RVNWAr"
      },
      "source": [
        "We can now load a mesh and rotate it using TensorFlow Graphics."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 0,
      "metadata": {
        "colab": {},
        "colab_type": "code",
        "id": "39Vm7iSONAHs"
      },
      "outputs": [],
      "source": [
        "# Download the mesh.\n",
        "# Courtesy of Keenan Crane www.cs.cmu.edu/~kmcrane/Projects/ModelRepository/.\n",
        "!wget -N https://storage.googleapis.com/tensorflow-graphics/notebooks/index/cow.obj\n",
        "# Load the mesh.\n",
        "mesh = trimesh.load(\"cow.obj\")\n",
        "mesh = {\"vertices\": mesh.vertices, \"faces\": mesh.faces}\n",
        "# Visualize the original mesh.\n",
        "_ = threejs_visualization.triangular_mesh_renderer(mesh, width=400, height=400)\n",
        "# Set the axis and angle parameters.\n",
        "axis = np.array((0., 1., 0.))  # y axis.\n",
        "angle = np.array((np.pi / 4.,))  # 45 degree angle.\n",
        "# Rotate the mesh.\n",
        "mesh[\"vertices\"] = tfg_transformation.axis_angle.rotate(mesh[\"vertices\"], axis,\n",
        "                                                        angle).numpy()\n",
        "# Visualize the rotated mesh.\n",
        "_ = threejs_visualization.triangular_mesh_renderer(mesh, width=400, height=400)"
      ]
    }
  ],
  "metadata": {
    "colab": {
      "collapsed_sections": [],
      "name": "_index.ipynb",
      "private_outputs": true,
      "provenance": [],
      "toc_visible": true
    },
    "kernelspec": {
      "display_name": "Python 3",
      "name": "python3"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}
